<?php

class MThanhVien extends CI_Model
{
	function danhsachthanhvien()
	{		
		return $this->db->get('thanhvien')->result();
	}
	
	function danhsachsanphamlimit($madm, $sodong, $dongbatdau)
	{
		$this->db->where('madm', $madm);
		$this->db->where('hienthi', 'true');		
		return $this->db->get('sanpham',$sodong, $dongbatdau)->result();
	}
	
	function danhsachAdmin()
	{
		return $this->db->get('sanpham')->result();
	}
	
	function xoathanhvien($masp)
	{
		$this->db->where('username', $username);
		$this->db->delete('thanhvien');
	}
	
	function capnhatdolan($masp, $tensp, $gia, $soluong, $hinh, $mota, $hienthi)
	{
		$this->db->where('masp', $masp);
		$this->db->set('tensp', $tendolan);
		$this->db->set('gia', $gia);
		$this->db->set('soluong', $soluong);
		$this->db->set('hinh', $hinh);
		$this->db->set('mota', $mota);
		$this->db->set('hienthi', $hienthi);
		$this->db->update('sanpham');
	}
	
	function thongtinthanhvien($username)
	{
		$this->db->where('username', $username);
		return $this->db->get('thanhvien')->row();
	}
	
	function themthanhvien($username, $password, $hoten, $ngaysinh, $email, $dienthoai, $diachi, $hinh)
	{
		$this->db->set('username', $username);
		$this->db->set('password', $password);
		$this->db->set('hoten', $hoten);
		$this->db->set('ngaysinh', $ngaysinh);
		$this->db->set('email', $email);
		$this->db->set('dienthoai', $dienthoai);
		$this->db->set('diachi', $diachi);
		$this->db->set('hinh', $hinh);
		$this->db->insert('thanhvien');
	}
	
	function danhsachsanphammoinhat()
	{
		$this->db->order_by('masp', 'desc');
		return $this->db->get('sanpham', 8, 0)->result();
	}
	
	function danhsachsanphamcungloai($madm)
	{
		$this->db->where('madm', $madm);
		$this->db->where('hienthi', 'true');
		$this->db->order_by('masp', 'desc');
		return $this->db->get('sanpham', 4, 0)->result();
	}
	
	function searchspUser($search)
	{
		$this->db->like('tensp', $search);
		$this->db->where('hienthi', 'true');
		return $this->db->get('sanpham')->result();
	}
	
	
}

?>